package main

import (
	_ "github.com/go-sql-driver/mysql" // 导入 MySQL 驱动
	"github.com/jinzhu/gorm"
)

func main() {
	// 用户名：密码@tcp(ip:port)/数据库?charset=utf8&parseTime=True&loc=Local
	db, err := gorm.Open("mysql", "root:123456@tcp(localhost:3306)/gorm_project?charset=utf8&parseTime=True&loc=Local")
	if err != nil {
		panic(err)
	}

	defer db.Close() // 关闭空闲的连接

	//var user []relation_table.User
	//db.Raw("select * from rel_user").Find(&user)
	//fmt.Println(user)

	// CRUD 用Exec
	//db.Exec("insert into rel_user (name,age) values(?,?)", "Alen", 32)
	//db.Exec("update   rel_user set name = ?  where id = ?", "hallen123", 13)
	//db.Exec("delete from user where id = ?", 14)

	// 返回单条
	//row, _ := db.Raw("select * from rel_user").Row()
	// 返回多条
	//row, _ := db.Raw("select * from rel_user").Rows()
	//fmt.Println(row)
}
